package com.ctshk.app.order.train.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.ChannelMainData;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.AppReq;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.req.pay.NotifyConsumeReq;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.train.dto.TrainOrderDetailAppDTO;
import com.ctshk.rpc.order.train.req.TrainCancelOrderAppReq;
import com.ctshk.rpc.order.train.req.TrainManualOrderAppReq;
import com.ctshk.rpc.order.train.req.TrainOrderWriteReq;
import com.ctshk.rpc.order.train.service.ITrainOrderAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@Api(tags = "火车服务—APP")
@RestController
@RequestMapping("/train-order/app")
public class TrainOrderH5Controller extends BaseController {

	@DubboReference
	ITrainOrderAppService trainOrderAppService;

	@ApiOperation(value="火车订单-填写订单信息", notes="火车订单-填写订单信息")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "填写订单信息", operDesc = "填写订单信息")
	@PostMapping("/write")
	public Result<Long> writeTrainOrder(@Valid @RequestBody TrainOrderWriteReq trainOrderWriteReq, @ApiIgnore AppReq appReq) {
		TokenUser user = getCurrentUserAllowNotLogIn(getRequest());
		return trainOrderAppService.writeTrainOrder(trainOrderWriteReq,user, appReq);
	}

	@ApiOperation(value="添加外挂单", notes="添加外挂单")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "添加外挂单", operDesc = "添加外挂单")
	@PostMapping("/save")
	public Result<Long> saveTrainMaunalOrder(@RequestBody @Valid TrainManualOrderAppReq trainOrderWriteReq) {
		TokenUser user = getCurrentUserAllowNotLogIn(getRequest());
		return trainOrderAppService.addTrainManualOrder(trainOrderWriteReq,user, ChannelMainData.APP_H5);
	}

	@ApiOperation(value="火车订单-支付订单", notes="火车订单-支付订单")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "火车订单-支付订单", operDesc = "火车订单-支付订单")
	@GetMapping("/pay")
	public Result trainOrderPay(@RequestParam("id") Long id, @RequestParam("paymentMethodCode") Integer paymentMethodCode) {
		return trainOrderAppService.trainOrderPay(id, paymentMethodCode);
	}

	/*@ApiOperation(value="火车订单-支付回调", notes="火车订单-支付回调")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "火车订单-支付回调", operDesc = "火车订单-支付回调")
	@PostMapping("/pay/notify")
	public Result trainOrderNotify(@RequestBody NotifyConsumeReq notifyConsumeReq) {
		return trainOrderAppService.trainOrderNotify(notifyConsumeReq);
	}*/

	@ApiOperation(value="火车订单-取消订单", notes="火车订单-取消订单")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "火车订单-取消订单", operDesc = "火车订单-取消订单")
	@PostMapping("/pay/cancel")
	public Result trainOrderCancel(@RequestBody @Valid TrainCancelOrderAppReq req) {
		return trainOrderAppService.trainOrderCancel(req);
	}

	@ApiOperation(value="火车订单-查看详情", notes="火车订单-查看详情")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "火车订单-详情页", operDesc = "火车订单-详情页")
	@GetMapping("/detail")
	public Result<TrainOrderDetailAppDTO> trainOrderDetail(@RequestParam("id") Long id) {
		return trainOrderAppService.trainOrderDetail(id);
	}

}
